﻿<UserControl x:Class="Snipps.Views.EditSnippetView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF45"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:Behaviors="clr-namespace:Snipps.Infrastructure.Behaviors"
             xmlns:Controls="clr-namespace:Snipps.Controls" xmlns:Langs="clr-namespace:Snipps.Langs"
             xmlns:Models="clr-namespace:Snipps.Core.Entities"
             d:DesignHeight="800"
             d:DesignWidth="300"
             mc:Ignorable="d">

    <UserControl.InputBindings>
        <KeyBinding Key="Enter"
                    Command="{Binding CurrentFilter.CompletionList.ActivateSelectedItemCommand}" />
        <KeyBinding Key="D"
                    Command="{Binding CurrentFilter.CompletionList.RemoveSelectedItemCommand}"
                    Modifiers="Control" />
        <KeyBinding Key="g"
                    Command="{Binding CurrentFilter.CompletionList.SelectFirstItemCommand}"
                    Modifiers="Control" />
        <KeyBinding Key="g"
                    Command="{Binding CurrentFilter.CompletionList.SelectLastItemCommand}"
                    Modifiers="Ctrl+Shift" />
        <KeyBinding Key="Down"
                    Command="{Binding CurrentFilter.CompletionList.SelectNextItemCommand}" />
        <KeyBinding Key="Up"
                    Command="{Binding CurrentFilter.CompletionList.SelectPrevItemCommand}" />
        <KeyBinding Key="N"
                    Command="{Binding CurrentFilter.CompletionList.SelectNextItemCommand}"
                    Modifiers="Control" />
        <KeyBinding Key="P"
                    Command="{Binding CurrentFilter.CompletionList.SelectPrevItemCommand}"
                    Modifiers="Control" />
        <KeyBinding Key="S"
                    Command="{Binding SaveCommand}"
                    Modifiers="Control" />
        <KeyBinding Key="Escape"
                    Command="{Binding CancelCommand}" />
    </UserControl.InputBindings>

    <i:Interaction.Behaviors>
        <Behaviors:ExecCmdFromInputBindingsOnPreviewKeyDownBahavior />
    </i:Interaction.Behaviors>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Controls:BusyTextBox x:Name="txt"
                              Grid.Row="0"
                              Text="{Binding SnippetName,
                                             UpdateSourceTrigger=PropertyChanged,
                                             ValidatesOnNotifyDataErrors=True}"
                              WatermarkText="{x:Static Langs:Lang.WatermarkSnippetName}">
            <i:Interaction.Behaviors>
                <Behaviors:BindableFocusBehavior FocusProperty="{Binding SnippetNameActive.IsActive, Mode=TwoWay}" />
            </i:Interaction.Behaviors>

        </Controls:BusyTextBox>

        <Controls:BusyTextBox x:Name="txt22"
                              Grid.Row="1"
                              IsSearching="{Binding ProgrammingLangFilter.IsBusy}"
                              Text="{Binding ProgrammingLangFilter.FilterText,
                                             UpdateSourceTrigger=PropertyChanged,
                                             ValidatesOnNotifyDataErrors=True}"
                              WatermarkText="{x:Static Langs:Lang.WatermarkProgrammingLang}">
            <i:Interaction.Behaviors>
                <Behaviors:BindableFocusBehavior FocusProperty="{Binding ProgrammingLangFilter.IsActive, Mode=TwoWay}" />
            </i:Interaction.Behaviors>

        </Controls:BusyTextBox>
        <Controls:TagsTextBox Grid.Row="2"
                              DisplayValueProperty="Name"
                              ObjectType="{x:Type Models:Tag}"
                              Tags="{Binding TagFilter.FilterTags}"
                              Text="{Binding TagFilter.FilterText,
                                             Mode=TwoWay,
                                             UpdateSourceTrigger=PropertyChanged}"
                              WatermarkText="{x:Static Langs:Lang.WatermarkTags}">

            <i:Interaction.Triggers>
                <i:EventTrigger EventName="RemoveItem">
                    <Command:EventToCommand Command="{Binding TagFilter.RemoveItemCommand}"
                                            PassEventArgsToCommand="True" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <i:Interaction.Behaviors>
                <Behaviors:BindableFocusBehavior FocusProperty="{Binding TagFilter.IsActive, Mode=TwoWay}" />
            </i:Interaction.Behaviors>
        </Controls:TagsTextBox>


        <Controls:Overlay Grid.Row="3"
                          IsOverlayVisible="{Binding IsCompletionListVisible,
                                                     Mode=TwoWay}"
                          MainContent="{Binding }"
                          OverlayContent="{Binding CurrentFilter.CompletionList}">
            <Controls:Overlay.MainContentTemplate>
                <DataTemplate>
                    <TextBox AcceptsReturn="True"
                             Style="{StaticResource ContentTextBoxStyle}"
                             Text="{Binding SnippetContent,
                                            UpdateSourceTrigger=PropertyChanged,
                                            ValidatesOnNotifyDataErrors=True}">
                        <i:Interaction.Behaviors>
                            <Behaviors:BindableFocusBehavior FocusProperty="{Binding SnippetContentActive.IsActive, Mode=TwoWay}" />
                            <Behaviors:InsertTabSpaceBehavior Key="Tab"
                                                              Modifiers="Control" />

                        </i:Interaction.Behaviors>
                    </TextBox>
                </DataTemplate>
            </Controls:Overlay.MainContentTemplate>
        </Controls:Overlay>


        <Grid Grid.Row="4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="btnSave"
                    Grid.Column="0"
                    Command="{Binding SaveCommand}"
                    Content="Save">
                <i:Interaction.Behaviors>
                    <Behaviors:BindableFocusBehavior FocusProperty="{Binding SaveButtonActive.IsActive, Mode=TwoWay}" />
                </i:Interaction.Behaviors>
            </Button>

            <Button Grid.Column="1"
                    Command="{Binding CancelCommand}"
                    Content="Cancel">
                <i:Interaction.Behaviors>
                    <Behaviors:BindableFocusBehavior FocusProperty="{Binding CancelButtonActive.IsActive, Mode=TwoWay}" />
                </i:Interaction.Behaviors>
            </Button>
        </Grid>

        <TextBlock Grid.Row="5"
                   Style="{StaticResource ErrorTextBlockStyle}"
                   Text="{Binding ValidationSummary,
                                  NotifyOnValidationError=True,
                                  UpdateSourceTrigger=PropertyChanged}" />

    </Grid>
</UserControl>